//
//  WebViewController.m
//  hellomui
//
//  Created by zhangtao on 15/10/28.
//  Copyright © 2015年 zt.td. All rights reserved.
//

#import "WebViewController.h"
#import "MainTabBarViewController.h"
@interface WebViewController ()<UIWebViewDelegate>
@property (strong, nonatomic) IBOutlet UIWebView *webview;
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *loading;

@end

@implementation WebViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _webview.delegate = self;
    [_webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://182.92.117.144:8080/study-manager/login/thirdLoginRe"]]];
    // Do any additional setup after loading the view.
}


- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

    BOOL bools = YES;
    
    if ([[[request URL] absoluteString] isEqualToString:@"http://182.92.117.144:8080/study-manager/login/study_manager://login/thirdLoginRe/success"]) {
        NSLog(@"success");
//        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"登陆成功" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
//        [alert show];
            MainTabBarViewController *main = [self.storyboard instantiateViewControllerWithIdentifier:@"main"];
            [self presentViewController:main
                               animated:YES completion:nil];

        NSLog(@"%@",request);

        bools = YES;
//        study_manager://login/thirdLoginRe/fail
    }else if ([[[request URL] absoluteString] isEqualToString:@"study_manager://login/thirdLoginRe/fail"]){
        NSLog(@"fail");
        NSLog(@"%@",request);
        bools = NO;
    }
   NSLog(@"~~~~~~%@",request);
//    else if([[[request URL] absoluteString] isEqualToString:@"study-manager:login/thirdLoginRe/fail"]){
        return bools;
    
}







- (void)webViewDidStartLoad:(UIWebView *)webView{
    NSLog(@"webViewDidStartLoad");
    _loading.hidden = NO;
    [_loading setCenter:CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2)];
    _loading.backgroundColor = [UIColor grayColor];
    [_loading setTintColor:[UIColor grayColor]];
    _loading.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
    [self.view addSubview:_loading];
    [_loading startAnimating];
    
}
- (void)webViewDidFinishLoad:(UIWebView *)web{
    NSLog(@"webViewDidFinishLoad");
    self.navigationItem.title=[web stringByEvaluatingJavaScriptFromString:@"document.title"];//获取当前页面的title
    [_loading stopAnimating];
    _loading.hidden = YES;
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}






/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
